package com.zf.zfed.audit.utils

import com.zf.sqlite.utils.AppDatabase
import com.zf.sqlite.utils.WhitelistEntity
import com.zf.sqlite.utils.BlacklistEntity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

object DatabaseInitializer {
    
    fun initializeTestData(database: AppDatabase) {
        CoroutineScope(Dispatchers.IO).launch {
            try {
                // 检查白名单是否已有数据
                val existingWhitelistData = database.whitelistDao().getAllWhitelist()
                if (existingWhitelistData.isEmpty()) {
                    // 添加白名单测试数据
                    val whitelistTestData = listOf(
                        WhitelistEntity(1, "Mate 60 Pro", "C0:18:50:04:5D:D7", "华为","备注1"),
                        WhitelistEntity(2, "NJzhongfu", "14:51:7E:08:32:F0", "H3H路由器","备注2"),
                        WhitelistEntity(1, "C0:18:59:67:5D:D5e", "", "","备注3"),
                        WhitelistEntity(3, "移动-5G-TDD", "N78", "3400-3500","备注4"),
                        WhitelistEntity(5, "音频", "80.5MHz", "",""),
                        WhitelistEntity(4, "AirPods Pro", "A4:C9:51:12:34:56", "苹果","备注备注")
                    )
                    
                    whitelistTestData.forEach { whitelistItem ->
                        database.whitelistDao().insertWhitelist(whitelistItem)
                    }
                }
                
                // 检查黑名单是否已有数据
                val existingBlacklistData = database.blacklistDao().getAllBlacklist()
                if (existingBlacklistData.isEmpty()) {
                    // 添加黑名单测试数据
                    val blacklistTestData = listOf(
                        BlacklistEntity(1, "未知设备", "00:11:22:33:44:55", "未知厂商", null, null, null, null, "可疑设备"),
                        BlacklistEntity(2, "未知WiFi", "AA:BB:CC:DD:EE:FF", "未知厂商", null, null, null, null, "恶意热点"),
                        BlacklistEntity(3, "未知蓝牙", "FF:EE:DD:CC:BB:AA", "未知厂商", null, null, null, null, "可疑蓝牙设备"),
                        BlacklistEntity(4, "未知移动设备", "11:22:33:44:55:66", "未知厂商", null, null, null, null, "可疑移动设备"),
                        BlacklistEntity(5, "未知音视频", "77:88:99:AA:BB:CC", "未知厂商", null, null, null, null, "可疑音视频设备")
                    )
                    
                    blacklistTestData.forEach { blacklistItem ->
                        database.blacklistDao().insertBlacklist(blacklistItem)
                    }
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }
}
